// localLifePackage/pages/writeOrder/writeOrder.js
var common = require("../../../common/common.js").common;

Page({
    /**
   * 页面的初始数据
   */
    data: {
        title: "订单详情",
        order_sn: 0,
        code: 0
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        let info = JSON.parse(decodeURIComponent(options.info));
        let that = this;
        console.log(options);
        that.setData({
            code: options.code,
            info: info
        });
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    confirmOrder: function() {
        var that = this;
        common.request({
            endpoint: "Localbusiness/order/order-write-off",
            method: "post",
            data: {
                order_sn: that.data.info.order_sn,
                code: that.data.code
            },
            success: res => {
                wx.showModal({
                    title: "提示",
                    content: res.message,
                    showCancel: false,
                    success(res) {
                        wx.navigateBack({
                            delta: 2
                        });
                    }
                });
            },
            fail: res => {
                wx.showModal({
                    title: "提示",
                    content: res.message,
                    showCancel: false,
                    success(res) {
                        wx.navigateBack({
                            delta: 2
                        });
                    }
                });
            }
        });
    }
});